home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Updates
/
Librarys
/
zee_ini_library
/
Sources
/
C
/
INI_Example
/
INI_Example.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-10-30
|
13KB
|
540 lines
/************************************************
*** Complex example program for INI library ***
*** © 1999 by Basty/Seasons ***
*** This program demonstrates the powerful ***
*** functions of the INI library ***
*** C/C++ version ***
*** StormC 3.0 DSK was used for development ***
************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <exec/types.h>
#include <exec/libraries.h>
#include <exec/lists.h>
#include <exec/nodes.h>
#include <libraries/dosextens.h>
#include <libraries/ini_lib.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/ini.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>
#include <intuition/intuition.h>
#include <graphics/rastport.h>
#include "INI_Example.h"
#define DefaultScrTitle "Example INI Test Screen © 1999 by Basty/Seasons"
#define DefaultWinTitle "Example INI Test Window © 1999 by Basty/Seasons"
struct INIScreen
{
struct MinList iniscr_ScrList;
};
struct ScreenList
{
struct MinNode iniscr_MinNode;
struct Screen *iniscr_ScreenPtr;
struct MinList iniscr_WinList;
};
struct ScreenWinList
{
struct MinNode scrwin_MinNode;
struct Window *scrwin_WindowPtr;
};
struct iniLibBase *INIBase;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct iniFile *DefINIFile;
struct ScreenList WBScreen =
{
{NULL, NULL},
NULL,
{(struct MinNode *) &(WBScreen.iniscr_WinList.mlh_Tail),NULL,(struct MinNode *) &(WBScreen.iniscr_WinList.mlh_Head)}
};
struct INIScreen Screens =
{
{(struct MinNode *) &(WBScreen.iniscr_MinNode.mln_Succ),NULL,(struct MinNode *) &(WBScreen.iniscr_MinNode.mln_Succ)}
};
UWORD DefaultColTab[256] =
{
0x000, 0xFFF, 0x777, 0xCCC,
0x444, 0x555, 0x666, 0x888,
0x111, 0x222, 0xAAA, 0x333,
0x999, 0xDDD, 0xEEE, 0xBBB
};
struct NewScreen NewScreenStr =
{
0, 0, /* LeftEdge, TopEdge */
640, 256, /* Width, Height */
4, /* Depth */
1, 0, /* DetailPen, BlockPen */
0x8000, /* ViewModes */
CUSTOMSCREEN, /* Type */
0, 0, /* TextAttr, DefaultTitle, */
0, 0 /* Gadgets, BitMap */
};
struct NewWindow NewWindowStr =
{
0, 0, /* LeftEdge, TopEdge */
640, 256, /* Width, Height */
1, 0, /* DetailPen, BlockPen */
0x200, 0x100F, /* IDCMPFlags, Flags */
0, 0, /* Gadget, Image */
0, 0, 0, /* Title, Screen, BitMap */
0, 0, /* MinWidth, MinHeight */
640, 256, /* MaxWidth, MaxHeight */
CUSTOMSCREEN /* Type */
};
unsigned char ScreenContext[16] = "Screen";
unsigned char WindowContext[16] = "Window";
void InitNode (struct List *NodeList)
{
NodeList->lh_Head = (struct Node *) &(NodeList->lh_Tail);
NodeList->lh_Tail = (struct Node *) NULL;
NodeList->lh_TailPred = (struct Node *) &(NodeList->lh_Head);
}
int ReadINIScreens (struct iniFile *iniFile)
{
struct iniContext *CurrentContext;
struct ScreenList *ScrStrBuf;
struct Screen *ScreenStr;
unsigned long ScrNumCols;
UWORD ScrColorTable[256];
/* Set FAIL error mark */
int rc = 20;
/* Start with first screen */
unsigned long CurrentScrNum = 1;
for (;;)
{
/* Convert screen number to ASCII using standard decimal format */
iniIntToStr ( ScreenContext+6, CurrentScrNum, INI_FORMAT_DEC, 0L, ' ');
/* Increment screen counter */
CurrentScrNum++;
/* Search for context and check if found */
if (!(CurrentContext = iniFindContext ( iniFile, ScreenContext, 0L)))
{
/* Found? No -> end of search */
rc = 0;
break;
}
/* Get left edge value or use default value of zero. */
NewScreenStr.LeftEdge = iniReadLong ( iniFile, ScreenContext,
"LeftEdge", 0L, 0L);
/* Get top edge value or use default value of zero. */
NewScreenStr.TopEdge = iniReadLong ( iniFile, ScreenContext,
"TopEdge", 0L, 0L);
/* Get width value or default width of 640 pixels. */
NewScreenStr.Width = iniReadLong ( iniFile, ScreenContext,
"Width", 640L, 0L);
/* Get height value or default height of 256 pixels. */
NewScreenStr.Height = iniReadLong ( iniFile, ScreenContext,
"Height", 256L, 0L);
/* Get depth value or default of 4 bitplanes (16 colors). */
NewScreenStr.Depth = iniReadLong ( iniFile, ScreenContext,
"Depth", 4L, 0L);
/* Get view modes value or default view mode of HIRES (0x8000). */
NewScreenStr.ViewModes = iniReadLong ( iniFile, ScreenContext,
"ViewModes", 0x8000L, 0L);
/* Get screen default title or use default string */
NewScreenStr.DefaultTitle = iniReadStr ( iniFile, ScreenContext,
"Title", DefaultScrTitle, 0L);
/* Copy all 256 default colors to updated color table */
memcpy (ScrColorTable,DefaultColTab,256);
ScrNumCols = (NewScreenStr.Depth < 8 ? 1L<<NewScreenStr.Depth : 256L);
/* Read all necessary color table entries into color table */
iniReadWordA ( iniFile, ScreenContext, "ColorTable", (WORD *) &ScrColorTable,
ScrNumCols, 0L);
/* We need storage buffers for our screens */
if (!(ScrStrBuf = (struct ScreenList *) iniAllocPMem (sizeof(struct ScreenList))))
{
/* Deallocate name string buffer. Don't forget ! */
iniFreeNameStr (NewScreenStr.DefaultTitle);
break;
}
/* Add them to list */
AddTail ((struct List *) &Screens.iniscr_ScrList, (struct Node *) ScrStrBuf);
/* Open the screen */
ScreenStr = OpenScreen (&NewScreenStr);
ScrStrBuf->iniscr_ScreenPtr = ScreenStr;
/* Initialize window node list */
InitNode ((struct List *) &(ScrStrBuf->iniscr_WinList));
if (ScreenStr == NULL)
{
/* Deallocate name string buffer. Don't forget */
iniFreeNameStr (NewScreenStr.DefaultTitle);
break;
}
LoadRGB4 (&ScreenStr->ViewPort, ScrColorTable, ScrNumCols);
}
return ( rc );
}
int ReadINIWindows (struct iniFile *iniFile)
{
struct iniContext *CurrentContext;
struct ScreenWinList *WinStrBuf;
struct Window *WindowStr;
struct ScreenList *scr;
unsigned long ScreenNum,i;
/* Set FAIL error mark */
int rc = 20;
/* Start with first window */
unsigned long CurrentWinNum = 1;
for (;;)
{
/* Convert window number to ASCII using standard decimal format */
iniIntToStr ( WindowContext+6, CurrentWinNum, INI_FORMAT_DEC, 0L, ' ');
/* Increment window counter */
CurrentWinNum++;
/* Search for context and check if found */
if (!(CurrentContext = iniFindContext ( iniFile, WindowContext, 0L)))
{
/* Found? No -> end of search */
rc = 0;
break;
}
/* Get left edge value or use default value of zero. */
NewWindowStr.LeftEdge = iniReadLong ( iniFile, WindowContext,
"LeftEdge", 0L, 0L);
/* Get top edge value or use default value of zero. */
NewWindowStr.TopEdge = iniReadLong ( iniFile, WindowContext,
"TopEdge", 0L, 0L);
/* Get width value or default width of 640 pixels. */
NewWindowStr.Width = iniReadLong ( iniFile, WindowContext,
"Width", 640L, 0L);
/* Get height value or default height of 256 pixels. */
NewWindowStr.Height = iniReadLong ( iniFile, WindowContext,
"Height", 256L, 0L);
/* Get IDCMP flags or default to 0x20000 (borderless). */
NewWindowStr.IDCMPFlags = iniReadLong ( iniFile, WindowContext,
"IDCMP", 0x20000, 0L);
/* Get window flags or default to 0x100F (Autoactivate + all gadgets) */
NewWindowStr.Flags = iniReadLong ( iniFile, WindowContext,
"Flags", 0x100FL, 0L);
/* Get screen default title or use default string */
NewWindowStr.Title = iniReadStr ( iniFile, WindowContext,
"Title", DefaultWinTitle, 0L);
/* Get min width value or default min width of 32 pixels. */
NewWindowStr.MinWidth = iniReadLong ( iniFile, WindowContext,
"MinWidth", 32L, 0L);
/* Get max width value or default max width of 640 pixels. */
NewWindowStr.MaxWidth = iniReadLong ( iniFile, WindowContext,
"MaxWidth", 640L, 0L);
/* Get min height value or default min height of 32 pixels. */
NewWindowStr.MinHeight = iniReadLong ( iniFile, WindowContext,
"MinHeig